package kk.yy.utilsdesign;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 使用SharePresenterUtils对数据进行本地化存储
 */
public class SharePresenterUtils {

    private static SharePresenterUtils mInstance;
    private SharePresenterUtils(){

    }
    public static SharePresenterUtils getInstance(){
        if(mInstance == null){
            mInstance = new SharePresenterUtils();
        }
        return mInstance;
    }
    public static void saveData(Context context, String table, String key, String value) {
        SharedPreferences sp = context.getSharedPreferences(table, context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString(key, value);
        edit.apply();
    }

    public static void saveData(Context context, String table, String key, boolean mBoolean) {
        SharedPreferences sp = context.getSharedPreferences(table, context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(key, mBoolean);
        edit.apply();
    }

    public static String getData(Context context, String table, String key) {
        SharedPreferences sp = context.getSharedPreferences(table, context.MODE_PRIVATE);
        String data = sp.getString(key, "");
        return data;
    }

    public static boolean getBooleanData(Context context, String table, String key) {
        SharedPreferences sp = context.getSharedPreferences(table, context.MODE_PRIVATE);
        boolean data = sp.getBoolean(key, false);
        return data;
    }
}
